<template>
  <!-- 查询医生（指定排班日期） -->
  <el-select v-model="curData" @change="onChange" value-key="id" clearable placeholder="请选择医生" style="width:100%">
    <el-option v-for="(item,index) in tableList" :key="index" :label="item.trueName" :value="item"></el-option>
  </el-select>
</template>
<script>
export default {
  props: ["value", "deptId", "day"],
  data() {
    return {
      curData: null,
      tableList: []
    };
  },
  mounted() {
    const th = this;
    th.getData(-1);
  },
  methods: {
    onChange() {
      const th = this;
      th.$emit("change", th.curData);
      if (th.curData) {
        th.$emit("input", th.curData.id);
      } else {
        th.$emit("input", null);
      }
    },
    getData(type) {
      const th = this;
      let j = {
        deptId: th.deptId,
        dateDay:
          th.day || th.$utils.FormatTime("yyyy-MM-dd", new Date().getTime()),
        pageNum: 1,
        pageSize: 200
      };
      th.$api.getDoctorScheduleListByDate(j).then(res => {
        if (res.executed) {
          th.tableList = res.dataBody.list;
        }
      });
    }
  },
  watch: {
    value(n) {
      const th = this;
      if (!n) th.curData = null;
    }
  }
};
</script>